//
//  CCSettingViewController.m
//  coninbase_data
//
//  Created by 2.5 on 2021/9/8.
//  Copyright © 2021 ChinaRainbow-iOS. All rights reserved.
//

#import "CCSettingViewController.h"
#import "hangePassViewController.h"
#import "CSuggesstionViewController.h"
@interface CCSettingViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)UITableView *tableView;
@property (nonatomic,strong)NSMutableArray *dataArray;

@end

@implementation CCSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self customeCCUI];
}
-(void)customeCCUI
{
    self.dataArray = [[NSMutableArray alloc] initWithArray:@[@"changepassWord",@"Feedback",@"sign out"]];
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.ccwidth, self.view.ccheight) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"set"];
    if(!cell){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"set"];
    }
    if(self.dataArray.count>indexPath.row){
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.textLabel.text = self.dataArray[indexPath.row];
    }
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row==0){
        hangePassViewController *cvc = [[hangePassViewController alloc] init];
        cvc.title = @"change pass";
        [self.navigationController pushViewController:cvc animated:YES];
    }else if(indexPath.row==1){
        CSuggesstionViewController *svc = [[CSuggesstionViewController alloc] init];
        svc.title = @"feedback";
        [self.navigationController pushViewController:svc animated:YES];
    }else{
        NSString *token = [[NSUserDefaults standardUserDefaults] objectForKey:@"cctoken"];
        if(token&&token.length){
            UIAlertController *avc =[UIAlertController alertControllerWithTitle:@"alert" message:@"Are you sure to exit?" preferredStyle:UIAlertControllerStyleAlert];
            
            UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                
            }];
            UIAlertAction *sure = [UIAlertAction actionWithTitle:@"sure" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"cctoken"];
                [self.navigationController popViewControllerAnimated:YES];
            }];
            [avc addAction:sure];
            [avc addAction:cancel];
            [self presentViewController:avc animated:YES completion:nil];
        }
    }
}
@end
